package com.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.dao.SysBoothDao;
import com.web.entity.SysBooth;
import com.web.entity.SysPoster;
import com.web.service.SysBoothService;

@Service
public class SysBoothServiceImpl implements SysBoothService {

	@Autowired
	private SysBoothDao sysBoothDao;

	@Override
	public List<SysBooth> queryAllsysBooth() {
		// TODO Auto-generated method stub
		return sysBoothDao.queryAllsysBooth();
	}

	@Override
	public PageInfo selectAllPoster(SysBooth sb, Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize); // 调用分页功能
		List<SysBooth> list = sysBoothDao.getAllBooth(sb); // 上面的分页会自动注入到本条查询中
		System.out.println(JSONObject.toJSON(list));
		PageInfo<SysBooth> pageInfo = new PageInfo<SysBooth>(list); // 获取分页信息
		System.out.println(JSONObject.toJSON(pageInfo));
		return pageInfo;
	}

	@Override
	public Map<String, Object> changeBoothState(Integer id, Integer state) {
		Map<String, Object> map = new HashMap<String, Object>();
		sysBoothDao.updateBoothState(id, state);
		map.put("result", 1);
		return map;
	}

	@Override
	public Map<String, Object> addBooth(SysBooth sysBooth) {
		sysBoothDao.addBooth(sysBooth);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", "success");
		return map;
	}

	@Override
	public Map<String, Object> delRowBooth(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		sysBoothDao.detBooth(id);
		map.put("result", 1);
		return map;
	}

}
